package com.fesine.learn.freemarker;

import freemarker.template.SimpleSequence;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @description: 自定义函数实现,实现TemplateMethodModelEx接口
 * @author: Fesine
 * @createTime:2017/5/8 22:49
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/5/8 22:49
 */
public class SortMethod implements TemplateMethodModelEx {
    @Override
    public Object exec(List arguments) throws TemplateModelException {
        SimpleSequence ss = (SimpleSequence) arguments.get(0);
        List<BigDecimal> list = ss.toList();
        Collections.sort(list, new Comparator<BigDecimal>() {
            @Override
            public int compare(BigDecimal o1, BigDecimal o2) {
                return o1.intValue()-o2.intValue();
            }
        });
        return list;
    }
}
